
using Abp.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace SOEI.Solution.DomainEntities.RoomSourceVerifiy.DomainService
{
    /// <summary>
    /// 领域服务层一个模块的核心业务逻辑
    ///</summary>
    public class RoomVerifyPropertyManager : DomainServiceBase, IRoomVerifyPropertyManager
    {

        private readonly IRepository<RoomVerifyProperty, long> _roomverifypropertyRepository;

        /// <summary>
        /// 【RoomVerifyProperty】的构造方法
        /// 通过构造函数注册服务到依赖注入容器中
        ///</summary>
        public RoomVerifyPropertyManager(IRepository<RoomVerifyProperty, long> roomverifypropertyRepository)
        {
            _roomverifypropertyRepository = roomverifypropertyRepository;
        }

        #region -------------------------------------------------辅助工具生成---------------------------------------------- 

        /// <summary>
        /// 返回列表查询用
        /// </summary>
        /// <returns></returns>
        public IQueryable<RoomVerifyProperty> QueryEntityListAsNoTracking()
        {

            var query = _roomverifypropertyRepository.GetAll().AsNoTracking()
                        .Select(x => new RoomVerifyProperty
                        {

                            PropertyOwnerName = x.PropertyOwnerName,
                            PropertyOwnerIdentityCard = x.PropertyOwnerIdentityCard,
                            RoomVerifyId = x.RoomVerifyId,
                        });
            return query;
        }

        /// <summary>
        /// 【RoomVerifyProperty】返回表达式数的实体信息即IQueryable类型
        /// </summary>
        /// <returns>IQueryable</returns>
        public IQueryable<RoomVerifyProperty> Query()
        {
            return _roomverifypropertyRepository.GetAll();
        }
        /// <summary>
        /// 【RoomVerifyProperty】返回即IQueryable类型的实体，不包含EF Core跟踪标记
        /// </summary>
        /// <returns>IQueryable</returns>
        public IQueryable<RoomVerifyProperty> QueryAsNoTracking()
        {
            return _roomverifypropertyRepository.GetAll().AsNoTracking();
        }
        /// <summary>
        /// 【RoomVerifyProperty】根据Id查询实体信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns>实体</returns>
        public async Task<RoomVerifyProperty> FindByIdAsync(long id)
        {
            var entity = await _roomverifypropertyRepository.GetAsync(id);
            return entity;
        }
        /// <summary>
        /// 【RoomVerifyProperty】检查实体是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns>bool</returns>
        public async Task<bool> IsExistAsync(long id)
        {
            var result = await _roomverifypropertyRepository.GetAll().AnyAsync(a => a.Id == id);
            return result;
        }
        /// <summary>
        /// 【RoomVerifyProperty】创建实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<RoomVerifyProperty> CreateAsync(RoomVerifyProperty entity)
        {
            entity.Id = await _roomverifypropertyRepository.InsertAndGetIdAsync(entity);
            return entity;
        }
        /// <summary>
        /// 【RoomVerifyProperty】更新实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task UpdateAsync(RoomVerifyProperty entity)
        {
            await _roomverifypropertyRepository.UpdateAsync(entity);
        }
        /// <summary>
        /// 【RoomVerifyProperty】删除实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteAsync(long id)
        {
            //TODO:删除前的逻辑判断，是否允许删除
            await _roomverifypropertyRepository.DeleteAsync(id);
        }
        /// <summary>
        /// 【RoomVerifyProperty】批量删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task BatchDelete(List<long> input)
        {
            //TODO:删除前的逻辑判断，是否允许删除
            await _roomverifypropertyRepository.DeleteAsync(a => input.Contains(a.Id));
        }
        #endregion


        #region -------------------------------------------------用户自定义------------------------------------------------
        /*请在此扩展领域服务接口*/

        /// <summary>
        /// 【RoomVerifyProperty】根据RoomVerifyId查询实体信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns>实体</returns>
        public async Task<RoomVerifyProperty> FindByRoomVerifyIdAsync(long RoomVerifyId)
        {
            var testEntity = await _roomverifypropertyRepository.GetAll().FirstOrDefaultAsync();

            var entity = await _roomverifypropertyRepository.GetAll().Where(a => a.RoomVerifyId == (int)RoomVerifyId).FirstOrDefaultAsync();

            return entity;
        }
        #endregion









    }
}
